Hello,
This may be a silly question, but I'm having trouble understanding the delete function.
You see, I created the function in which I compare two objects with an attribute with common values and the oldest would be deleted.
But the function doesn't work.
I just want to know if the error is in the delete part. Or if I got that right.
Thanks
void delete(Object obj1, obj2)
{
m = current Module
string idStr
string auxtag2
auxtag2 = obj2."Old tag" ""
for obj1 in m do {
idStr = obj1."Old tag" ""
if (idStr == auxtag2) {
if(obj1."Last Modified On" "" < dateAndTime(today)""){
delete obj1
}
if(obj2."Last Modified On" "" < dateAndTime(today)""){
delete obj2
}
}
}
}
braolive - Thu Oct 24 14:01:38 EDT 2013 |
Re: Delete obj Your code has some serious problems nothing to do with "delete(Object)". [1] It doesn't make sense to accept "obj1" as a parameter, and then use that variable in a loop.
[2] You don't want objects in the "current" module, you want objects in the same module as obj2: [3] I think you want to compare the "Last Modified On" date of the two objects; comparing it to "today" will almost always result in deleting both objects.
[4] The "for o in m do" loop puts you at the mercy of the current view settings, especially the current Filter. You probably want: [5] Use "hardDelete(Object)" [6] flushDeletions() when done. [7] if (!isEdit(m)) then errorBox("Open module edit") -Louie |
Re: Delete obj llandale - Thu Oct 24 14:49:05 EDT 2013 Your code has some serious problems nothing to do with "delete(Object)". [1] It doesn't make sense to accept "obj1" as a parameter, and then use that variable in a loop.
[2] You don't want objects in the "current" module, you want objects in the same module as obj2: [3] I think you want to compare the "Last Modified On" date of the two objects; comparing it to "today" will almost always result in deleting both objects.
[4] The "for o in m do" loop puts you at the mercy of the current view settings, especially the current Filter. You probably want: [5] Use "hardDelete(Object)" [6] flushDeletions() when done. [7] if (!isEdit(m)) then errorBox("Open module edit") -Louie I'm really having difficult in this. What I'm trying to do is look for objects that have the same "old tag" attribute and delete the older one. I'm happy to know that the error isn't in the delete part. At least that I got right. But the loop to find the similar ones is where I'm stuck.
But thank you. |
Re: Delete obj braolive - Fri Oct 25 08:05:13 EDT 2013 I'm really having difficult in this. What I'm trying to do is look for objects that have the same "old tag" attribute and delete the older one. I'm happy to know that the error isn't in the delete part. At least that I got right. But the loop to find the similar ones is where I'm stuck.
But thank you.
( Hi !! |
Re: Delete obj llandale - Thu Oct 24 14:49:05 EDT 2013 Your code has some serious problems nothing to do with "delete(Object)". [1] It doesn't make sense to accept "obj1" as a parameter, and then use that variable in a loop.
[2] You don't want objects in the "current" module, you want objects in the same module as obj2: [3] I think you want to compare the "Last Modified On" date of the two objects; comparing it to "today" will almost always result in deleting both objects.
[4] The "for o in m do" loop puts you at the mercy of the current view settings, especially the current Filter. You probably want: [5] Use "hardDelete(Object)" [6] flushDeletions() when done. [7] if (!isEdit(m)) then errorBox("Open module edit") -Louie Hello, I'm surprised Louie didn't mention to not delete the loop variable obj1 inside the loop. I think it would work ok if you deleted the object in the loop and then do the flushDeletions after the loop is completed. The normal practice would be to add it to a skip list and then after the loop is completed, delete the objects in the skip list. Greg |
Re: Delete obj pommCannelle - Fri Oct 25 08:20:51 EDT 2013
( Hi !! If you can help...I appreciate it. Attachments copyNEW.dxl |
Re: Delete obj braolive - Fri Oct 25 09:28:49 EDT 2013 If you can help...I appreciate it. I did not run the code. I'm looking only at function "del()". I think you want something like this:
I have doubts that "Last Modified Date" is a suitable condition. What if someone just modified the wrong object? I think you want function lastModifiedTime(Object) instead of o."Last Modified On" (but I've never actually used it) -Louie -Louie |
Re: Delete obj GregM_dxler - Fri Oct 25 09:01:14 EDT 2013 Hello, I'm surprised Louie didn't mention to not delete the loop variable obj1 inside the loop. I think it would work ok if you deleted the object in the loop and then do the flushDeletions after the loop is completed. The normal practice would be to add it to a skip list and then after the loop is completed, delete the objects in the skip list. Greg
( well ... the link treatment is missing ... You may have some problem if you try to delete linked objects, and if you don't then you'll have some problems with links without available target. |
Re: Delete obj pommCannelle - Thu Oct 31 10:17:17 EDT 2013
( well ... the link treatment is missing ... You may have some problem if you try to delete linked objects, and if you don't then you'll have some problems with links without available target. Yes, pommCannelle your right. Both outlinks and inlinks need to be deleted before the object is deleted. Outlinks might not be needed to be deleted, but I've seen some problems if we don't do that, so I just make it a habit. Of course, in order to delete inlinks, you need to open up the source module in editable mode. Another thing to worry about is that when an object is deleted, all of it's children get deleted as well. So not only do you need to check and delete in/out links in the object but also delete in/out links in the children. Something that bite me in the past. I'll attach a snippet of code where I do object deleting with checking and deleting in/out links. It is not workable code, as I just copied the pertainent parts. Note too, that this does not include the use of skip lists. Hope this helps, Greg Attachments Del_Obj.dxl |